//
//  KHJUserInfo.m
//  kanhujia
//
//  Created by lxl on 2018/3/27.
//  Copyright © 2018年 lxl. All rights reserved.
//

#import "KHJUserInfo.h"
//#import "KHJLoginViewController.h"
#import "TYZNavigationController.h"
@implementation KHJUserInfo
+ (void)loginWithUserAccount:(NSString *)uesrAccount password:(NSString *)password remenber:(BOOL)remenber complement:(void(^)(NSString *result))complement {
    NSString *port = [NSString stringWithFormat:@"%@?userAccount=%@&userPwd=%@&rememberMe=%@", Request_Login, uesrAccount, password, remenber ? @"true" : @"false"];
    [TYZNetworkingTool post:port params:nil success:^(NSString *string, NSDictionary *data) {
        if ([data isKindOfClass:[NSDictionary class]]) {
            UserInfo = [KHJUserInfo mj_objectWithKeyValues:data];
            if (complement) {
                complement(Request_Success);
            }
        } else {
            if (complement) {
                complement(Request_Failed);
            }
        }
    } failure:^(NSString *error) {
        if (complement) {
            if ([error isEqualToString:Request_PwdError]) {
                complement(@"密码错误");
            } else if ([error isEqualToString:Request_NoAccount]) {
                complement(@"账号不存在");
            } else {
                complement(@"登录失败，请稍后再试");
            }
        }
    }];
}
+ (void)logoutWithComplement:(void(^)(BOOL result))complement {
//    [[TYZSystemDialog getCurrentViewController] presentViewController:[[TYZNavigationController alloc] initWithRootViewController:[[KHJLoginViewController alloc] init]] animated:YES completion:^{
//        [TYZNetworkingTool post:Request_Logout params:nil success:^(NSString *string, id data) {
//            UserInfo = nil;
//            if (complement) {
//                complement(YES);
//            }
//        } failure:^(NSString *error) {
//            if (complement) {
//                complement(NO);
//            }
//        }];
//    }];
    CoreInfo.isLogined = NO;
    CoreInfo.userInfo = nil;
    CoreInfo.session_id = nil;
    CoreInfo.rememberMe = nil;
}
@end
